<?php
// +----------------------------------------------------------------------
// | Description: 系统用户
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\AdminService;
use app\admin\validate\AdminValidate;
use common\controller\AdminAuthController;
use common\Token\Token;


class Admin extends AdminAuthController
{

    public function detail()
    {
        $AdminService = AdminService::instance();
        $user = Token::instance()->getUserInfo();
        $uid = $user[$user->getPk()];
        $data = $AdminService->getMore($uid);
        $data['userInfo']->hidden(['groups']);
        return $this->json_responce($data);
    }

    public function refresh()
    {
        $AdminService = AdminService::instance();
        $user = Token::instance()->getUserInfo();
        $uid = $user[$user->getPk()];
        $authData = $AdminService->createJwt($user);
        return $this->json_responce( $authData);
    }

    public function index()
    {
        $AdminService = AdminService::instance();
        $get = input_extract_rule([
            'page' => 1,
            'keywords' => '',
            'limit' => 20,
            'group_id' => '',
            'structure_id' => '',
            'post_id' => '',
        ], 'get');
        AdminValidate::instance()->runCheck($get, '', __FUNCTION__);
        $data = $AdminService->getDataList($get);
        return $this->json_responce($data);
    }

    public function read()
    {
        $AdminService = AdminService::instance();
        $get = input_extract_rule([
            'id' => '',
        ], 'param');
        AdminValidate::instance()->runCheck($get, '', __FUNCTION__);
        $data = $AdminService->read($get['id']);
        return $this->json_responce($data);
    }

    public function save()
    {
        $AdminService = AdminService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $AdminService->createData($param);
        return $this->json_responce();
    }

    public function update()
    {
        $AdminService = AdminService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $AdminService->updateByID($param);
        return $this->json_responce();
    }

    public function delete()
    {
        $AdminService = AdminService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $AdminService->delByID($param);
        return $this->json_responce();
    }

    public function deletes()
    {
        $AdminService = AdminService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $AdminService->delByIDs($param);
        return $this->json_responce();
    }

    public function enables()
    {
        $AdminService = AdminService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $AdminService->enableByIDs($param);
        return $this->json_responce();
    }

}
 